/*
 * QTXpost - a Qt-based blog client.
 * Copyright (C) 2010 Helen Sommer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (in COPYING); if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA  02111-1307  USA
 *
 * The project is hosted on http://code.google.com/p/qtxpost
 */

#include "MainWindow.h"
#include "Config.h"
#include "version.h"

QApplication *app;
MainWindow *root = 0;
Config *config;

int main(int argc, char** argv)
{
  app = new QApplication(argc,argv);
  QString configDirectory = QString("");  
  if (app->arguments().size()>1) {
    for (int i = 1; i<app->arguments().size(); i++) {
      QString str = app->arguments().at(i);
      if (str.startsWith("--config=")) {
        configDirectory = str.section('=',1,1);
        break;
      }
      else if (str.startsWith("--help")) {
        printf("Usage: qtxpost [--config=CONFIG_DIRECTORY]\n");
        exit(0);
      }
    }
  }

/*  app->setStyle(new QPlastiqueStyle);
  app->setFont(QFont("Helvetica", 12, QFont::Normal)); */
  //  app->setStyleSheet(":/qss/default.qss");

  if (app->styleSheet() == "") {
    QFile file(":/qss/default.qss");
    file.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(file.readAll());
    app->setStyleSheet(styleSheet);
  }

  config = new Config(configDirectory);
  if (config->error) {
    config->show();
  }
  else{
    root = new MainWindow();
    app->connect(app, SIGNAL(lastWindowClosed()), root, SLOT(close())); 
    root->show();
  }
  return app->exec();
}

